// Decompiled by DJ v3.11.11.95 Copyright 2009 Atanas Neshkov  Date: 1/30/2010 10:58:59 PM
// Home Page: http://members.fortunecity.com/neshkov/dj.html  http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   MazeSolutionImpl.java


public class MazeSolutionImpl
    implements MazeSolution, Cloneable
{

    public MazeSolutionImpl(int i, int j, int k, int l, int i1, int j1)
    {
        xPositions = new int[10000];
        yPositions = new int[10000];
        width = i;
        height = j;
        xPositions[0] = k;
        yPositions[0] = l;
        endX = i1;
        endY = j1;
        length = 1;
    }

    protected MazeSolutionImpl(MazeSolutionImpl mazesolutionimpl)
    {
        xPositions = new int[10000];
        yPositions = new int[10000];
        width = mazesolutionimpl.width;
        height = mazesolutionimpl.height;
        endX = mazesolutionimpl.endX;
        endY = mazesolutionimpl.endY;
        xPositions = (int[])mazesolutionimpl.xPositions.clone();
        yPositions = (int[])mazesolutionimpl.yPositions.clone();
        length = mazesolutionimpl.length;
    }

    public Object clone()
    {
        return new MazeSolutionImpl(this);
    }

    public int getMazeWidth()
    {
        return width;
    }

    public int getMazeHeight()
    {
        return height;
    }

    public boolean solutionComplete()
    {
        return getLastXPosition() == endX && getLastYPosition() == endY;
    }

    public int getLastXPosition()
    {
        return xPositions[length - 1];
    }

    public int getLastYPosition()
    {
        return yPositions[length - 1];
    }

    public int[] getXPositions()
    {
        int ai[] = new int[length];
        for(int i = 0; i < length; i++)
            ai[i] = xPositions[i];

        return ai;
    }

    public int[] getYPositions()
    {
        int ai[] = new int[length];
        for(int i = 0; i < length; i++)
            ai[i] = yPositions[i];

        return ai;
    }

    public int getLength()
    {
        return length;
    }

    public void backUp()
    {
        if(length > 1)
            length--;
        else
            throw new MazeSolutionException("cannot back up a solution that has only one position");
    }

    public void moveNorth()
    {
        if(yPositions[length - 1] > 0)
        {
            xPositions[length] = xPositions[length - 1];
            yPositions[length] = yPositions[length - 1] - 1;
            length++;
        } else
        {
            throw new MazeSolutionException("cannot move north from (" + xPositions[length - 1] + "," + yPositions[length - 1] + ")");
        }
    }

    public void moveSouth()
    {
        if(yPositions[length - 1] < height - 1)
        {
            xPositions[length] = xPositions[length - 1];
            yPositions[length] = yPositions[length - 1] + 1;
            length++;
        } else
        {
            throw new MazeSolutionException("cannot move south from (" + xPositions[length - 1] + "," + yPositions[length - 1] + ")");
        }
    }

    public void moveEast()
    {
        if(xPositions[length - 1] < width - 1)
        {
            xPositions[length] = xPositions[length - 1] + 1;
            yPositions[length] = yPositions[length - 1];
            length++;
        } else
        {
            throw new MazeSolutionException("cannot move east from (" + xPositions[length - 1] + "," + yPositions[length - 1] + ")");
        }
    }

    public void moveWest()
    {
        if(xPositions[length - 1] > 0)
        {
            xPositions[length] = xPositions[length - 1] - 1;
            yPositions[length] = yPositions[length - 1];
            length++;
        } else
        {
            throw new MazeSolutionException("cannot move west from (" + xPositions[length - 1] + "," + yPositions[length - 1] + ")");
        }
    }

    private int width;
    private int height;
    private int endX;
    private int endY;
    private int xPositions[];
    private int yPositions[];
    private int length;
}
